package com.zzw.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.zzw.bean.User;
import com.zzw.service.imple.IUserService;
import com.zzw.utils.Result;
import com.zzw.utils.ResultEnum;
import com.zzw.utils.ResultUtils;

@Controller
public class IndexController {
	
	@Autowired
	IUserService userService;
	
	
	/**
	 * 调用登陆页
	 * */
	@RequestMapping("/toLogin.do")
	public ModelAndView toLogin() {
		ModelAndView mv=new ModelAndView();
		mv.setViewName("login");
		return mv;
	}
	
	/**
	 * 登录验证
	 * */
	@RequestMapping("/checkLogin.do")
	@ResponseBody
	public Result checkLogin(User user) {
		Result result=null;
		User u=userService.checkLogin(user);
		if(u!=null) {
			result=ResultUtils.success(u);
		}else {
			result= ResultUtils.success();
			result.setCode(ResultEnum.LOGIN_FAILS.getCode());
			result.setMsg(ResultEnum.LOGIN_FAILS.getMsg());
		}
		
		return result;
	}
	
	
	
	
	
	/**
	 * 调用首页
	 * */
	@RequestMapping("/index.do")
	public ModelAndView index() {
		ModelAndView mv=new ModelAndView();
		mv.setViewName("index");
		return mv;
	}
	
	/**
	 * 空白页
	 * */
	@RequestMapping("/statics.do")
	public ModelAndView statics() {
		ModelAndView mv=new ModelAndView();
		mv.setViewName("statics");
		return mv;
	}
	

}
